package io.polly.ldz.reactor.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.polly.ldz.reactor.config.KafkaConfig;
import io.polly.ldz.reactor.entity.Question;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @Author ldz112@163.com
 * @Classname KafkaConsumer
 * @Version V1.0
 * @Description 简单消费
 * @Date 2024/9/29 20:33
 * Copyright (C) 2023 All Rights Reserved
 */
@Component
@Slf4j
public class KafkaConsumer {

    //监听消费
    @KafkaListener(topics = {KafkaConfig.QUESTION_TOPIC})
//    @SendTo("sb_topic2")
//    @KafkaListener(topicPartitions = {@TopicPartition(topic = "test",partitions = {"1"})})//
//    @KafkaListener(id = "consumer2", topics = {"sb_topic"}, groupId = "sb_group")
    public void onNormalMessage(String record, Acknowledgment ack) {
        Question question = JSONObject.parseObject(record,Question.class);
        log.info("简单消费：" + JSON.toJSONString(question));
        ack.acknowledge();
    }
}
